<?php
// +----------------------------------------------------------------------
// | Jqcms [ Avenue to Jane ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://jqcms.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: hyacinth <845077398@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\BaseController;

class CommentController extends BaseController {
    
    public function index(){
       
        $comments = M('Comment');
        $where = "";
        $count = $comments->where($where)->count();
        $p = getpage($count,10);
        $list = $comments->field(true)->where($where)->order('id desc,dateline desc')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list);
        $this->assign('page', $p->show());
        $this->display();
        
    }
    
    public function audit($id){
        
        $comment = M('Comment');
        $audit = $comment->where(array('id'=>$id))->setField('state',1);
        if ($audit){
            $this->success('审核成功!');
        }else {
            $this->error('审核失败!');
        }
        
    }
    
    public function selectAudit(){
        
        $comment = M('Comment');
        foreach (I('id') as $v){
            $comment->where(array('id'=>$v))->setField('state',1);
        }
        $this->success('批量审核成功!');
       
    }
    
    public function del($id){
        
        $comment = M('Comment');
        $del = $comment->delete($id);
        if($del !==0 && $del !==false){
            $this->success('删除成功!');
        }else {
            $this->error('删除失败!');
        }
         
    }
    
    public function delselect(){
    
        $comment = M('Comment');
        $idstr = implode(',', I('id'));
        $del = $comment->delete($idstr);
        if($del !==0 && $del !==false){
            $this->success('删除成功!');
        }else {
            $this->error('删除失败!');
        }
    
    }
    
  
    
}